home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Systemmonitors / AskTask / at_kill.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  5KB  |  152 lines

  1. /* at_kill.c */
  2. /*************************************************************************
  3.  ***                    AskTask Kill Process Module                    ***
  4.  *** Date begun: 2/4/89.                                               ***
  5.  *** Last modified: 2/4/89.                                            ***
  6.  *************************************************************************/
  7. /*** The idea is to reset the task's PC to the address of the code     ***
  8.  *** array, which calls the DOS function Exit(). This works! It should ***
  9.  *** not be used while the task owns say, the blitter. Also, using the ***
  10.  *** abort signal is better if the task cares about such things (say a ***
  11.  *** Lattice C program during level 2(?) IO). It works best on pure    ***
  12.  *** processing tasks, for example during an infinite loop that does   ***
  13.  *** not do drawing or IO.                                             ***
  14.  *** Cut rmv(), changepri() & setsignal() into this module.            ***
  15.  *************************************************************************/
  16.  
  17. #include "asktask.h"
  18.  
  19. extern struct Window    *Window;
  20. extern int          ct;
  21. extern struct Task  *task[NUM_TASKS];
  22. extern char         *notaskerror;
  23. extern char         mypri;
  24. extern struct Task  *me;
  25.  
  26. extern void putmessage(char *,int);
  27. extern int  yesno();
  28. extern void gettasks();
  29. extern void puttasks();
  30. extern void puttaskdata();
  31. extern unsigned long    bitsput(char *);
  32. extern void putbits(char *,unsigned long);
  33. extern char getchfromw();
  34.  
  35. static UWORD   code[6] = {
  36.     0x721e,                 /* moveq    #30,d1          */
  37.     0x2c7c,0x0000,0x0000,   /* movea.l  #00000000,a6    */
  38.     0x4eee,0xff70           /* jmp      $ff70(a6)       */
  39.         /* I would like to know how Exit() finds out which process this
  40.          * task belongs to. */
  41. };
  42.  
  43. void    rmv();          /* Remove current task with RemTask() */
  44. void    kill();         /* Remove a task with Exit() function */
  45. void    setsignal();    /* Alter signal values for current task */
  46. void    changepri();    /* Change task's priority */
  47.  
  48. void    rmv() /*=========================================================*/
  49. {
  50.     if (ct < 0) {
  51.         putmessage(notaskerror,3);
  52.         return;
  53.     }
  54.     putmessage("Are you sure you want to RemTask() the current task (y/n)?",3);
  55.     if (!yesno()) {
  56.         putmessage("",1);
  57.         return;
  58.     }
  59.     RemTask(task[ct]);
  60.     gettasks();
  61.     puttasks();
  62.     puttaskdata();
  63.     putmessage("RemTask() completed.",1);
  64. }
  65.  
  66. void    setsignal() /*===================================================*/
  67. {
  68. unsigned long   *l,lv;
  69. int     loop;
  70. char    ch,buf[40];
  71.     putmessage("",1);
  72.     if (ct < 0) {
  73.         putmessage(notaskerror,3);
  74.         return;
  75.     }
  76.     putmessage("Which signal (Alloc/Wait/Recvd/Except/None) ?",3);
  77.     loop = 1;
  78.     while (loop) {
  79.         ch = getchfromw();
  80.         switch (ch) {
  81.             case (0x20): l = &(task[ct]->tc_SigAlloc);  loop = 0; break;
  82.             case (0x11): l = &(task[ct]->tc_SigWait);   loop = 0; break;
  83.             case (0x13): l = &(task[ct]->tc_SigRecvd);  loop = 0; break;
  84.             case (0x12): l = &(task[ct]->tc_SigExcept); loop = 0; break;
  85.             case (0x45):
  86.             case (0x36): putmessage("",1); return;    /* n */
  87.         }
  88.     }
  89.     putbits(&buf[0],*l);
  90.     putmessage("Enter the signal bit values:",1);
  91.     input(Window,buf,buf,"01",236,135,32,1,0);
  92.     lv = bitsput(buf);
  93.     *l = lv;
  94.     puttaskdata();
  95. }
  96.  
  97. void    changepri() /*===================================================*/
  98. {
  99. int     pri,newpri;
  100. char    buf[11];
  101.     putmessage("",1);
  102.     if (ct < 0) {
  103.         putmessage(notaskerror,3);
  104.         return;
  105.     }
  106.     pri = (int)task[ct]->tc_Node.ln_Pri;
  107.     newpri = pri;
  108.     sprintf(buf,"%d",pri);
  109.     putmessage("Change priority to :",1);
  110.     input(Window,buf,buf,"0123456789-+",172,135,4,1,0);
  111.     putmessage("",1);
  112.     if (!buf[0]) return;
  113.     sscanf(buf,"%d",&newpri);
  114.     if (newpri == pri) return;
  115.     if (newpri < -128) newpri = -128;
  116.     else if (newpri > 122) newpri = 122;
  117.     if (newpri > mypri) {
  118.         mypri = newpri + 5; /* Don't block myself with task's priority. */
  119.         SetTaskPri(me,mypri);
  120.     }
  121.     SetTaskPri(task[ct],(char)newpri);
  122.     puttaskdata();
  123. }
  124.  
  125. void    kill() /*========================================================*/
  126. {
  127. unsigned long   *lp;
  128. ULONG   *stk;
  129.     if (ct < 0) {
  130.         putmessage(notaskerror,3);
  131.         return;}
  132.     putmessage("Are you sure you want to try Exit()ing this process (y/n)?",3);
  133.     if (!yesno()) {
  134.         putmessage("",1);
  135.         return;}
  136.     lp = (unsigned long *)&code[2];     /* Set up code for dosbase value */
  137.     *lp = (unsigned long)DOSBase;
  138.  
  139.     Disable();                          /* Now get at task's pc          */
  140.     stk = (ULONG *)task[ct]->tc_SPReg;  /* Have stack pointer...         */
  141.     stk[0] = (ULONG)&code[0];           /* ...will travel. Here I go.... */
  142.     Enable();
  143.     putmessage("",1);
  144. }
  145.  
  146. /******************** CONTEXT SWITCH STACK CONTENTS **********************
  147.  *** As far as I can tell, the data on the stack is:                   ***
  148.  ***        0 = (long) pc                                              ***
  149.  ***        1 = (word) status reg                                      ***
  150.  ***        2... = other registers.                                    ***
  151.  *************************************************************************/
  152.